package server

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"specifica_video_manage/client"
	"specifica_video_manage/model"
)

type ResultServer struct{}

func (r ResultServer) SaveVideo(c *gin.Context) {
	videoInfo := model.VideoModel{}
	err := c.BindJSON(&videoInfo)
	fmt.Printf("SaveVideo.videoInfo: %#v", videoInfo)
	if err != nil {
		fmt.Println("SaveVideo bind json catch error :", err.Error())
		c.JSON(500, model.Resp{}.Error(err.Error()))
		return
	} else {
		go client.MysqlTaskClient{}.CreateVideo(&videoInfo)
		c.JSON(200, model.Resp{}.Received(&videoInfo))
	}
}

func (r ResultServer) SaveAuthor(c *gin.Context) {
	authorInfo := model.AuthorModel{}
	err := c.BindJSON(&authorInfo)

	if err != nil {
		fmt.Println("SaveAuthor bind json catch error :", err.Error())
		c.JSON(500, model.Resp{}.Error(err.Error()))
		return
	} else {
		//fmt.Printf("SaveAuthor.authorInfo: %#v", authorInfo)
		go client.MysqlTaskClient{}.CreateAuthor(&authorInfo)
		//err :=  client.MysqlTaskClient{}.CreateAuthor(&authorInfo)
		//if err != nil {
		//	fmt.Println(err)
		//}
		c.JSON(200, model.Resp{}.Received(authorInfo))
	}
}
